﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;

namespace FRS.FileProcessor
{
    /// <summary>
    /// FakeSxDocument(后缀名为.sxd)只会保存AxSceneControl.Scene的相关信息，
    /// 并不包含有效的Scene Document，所以不能被ArcScene打开！！！
    /// </summary>
    public static class FakeSxDocumentProcessor
    {
        /// <summary>
        /// 加载fake sxd文档
        /// </summary>
        /// <param name="axSceneControl">调用对象</param>
        /// <param name="fileName">文件名称</param>
        /// <returns>加载成功返回TRUE，否则返回FALSE</returns>
        public static bool LoadFakeSxFile(this AxSceneControl axSceneControl, string fileName)
        {
            if (fileName == string.Empty || fileName == null)
            {
                return false;
            }
            else
            {
                IMemoryBlobStream mbStream = new MemoryBlobStreamClass();
                IObjectStream objectStream = new ObjectStreamClass();
                IPersistStream persistStream = axSceneControl.Scene as IPersistStream;

                objectStream.Stream = mbStream;
                mbStream.LoadFromFile(fileName);
                persistStream.Load(objectStream);

                return true;
            }
        }

        /// <summary>
        /// 保存fake sxd文档
        /// </summary>
        /// <param name="axSceneControl">调用对象</param>
        /// <param name="fileName">文件名</param>
        /// <returns>保存成功返回TRUE，否则返回FALSE</returns>
        public static bool SaveFakeSxFile(this AxSceneControl axSceneControl, string fileName)
        {
            if (fileName == string.Empty || fileName == null)
            {
                return false;
            }
            else
            {
                IMemoryBlobStream mbStream = new MemoryBlobStreamClass();
                IObjectStream objectStream = new ObjectStreamClass();
                IPersistStream persistStream = axSceneControl.Scene as IPersistStream;

                objectStream.Stream = mbStream;
                persistStream.Save(objectStream, 1);
                mbStream.SaveToFile(fileName);

                return true;
            }
        }
    }
}
